﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Net;


namespace TestStarter.Util
{
    public class ValidateUtility
    {
        public static IList<string> ValidateSettings(string url, string folderPath)
        {
            IList<string> errorList = new List<string>();
            WebRequest request = WebRequest.Create(url);
            HttpWebResponse response ;
            try
            {
                response = (HttpWebResponse)request.GetResponse();
                if (response == null || response.StatusCode != HttpStatusCode.OK)
                {
                    errorList.Add("URL is not accessible");
                }
            }
            catch
            {
                errorList.Add("URL is not accessible");
            }
           

            if (!Directory.Exists(folderPath))
            {
                errorList.Add("Folder does not exist");
            }

            return errorList;
        }

        public static string ListToString(IList<string> list)
        {
            string s = "";
            for (int i = 0; i < list.Count; i++)
            {
                if (i == (list.Count - 1))
                    s += list[i];
                else
                    s += list[i] + ", ";
            }

            return s;
        }
    }
}
